<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app"></div>

  <script src="../js/react.development.js"></script>
  <script src="../js/react-dom.development.js"></script>
  <script src="../js/babel.min.js"></script>
  <script src="../js/prop-types.js"></script>
  <script type="text/babel">

    class Form extends React.Component{
      state = {
        username:'',
        password:''
      }
      handleLogin = (e)=>{

        e.preventDefault()
        const { username,password} = this.state
        alert(`表单提交的用户名是 ${username}，密码是 ${password}`)
      }

      saveUsername = (e)=>{
        this.setState({
          username: e.target.value
        })
      }
      savePassword = (e)=>{
        this.setState({
          password: e.target.value
        })
      }

      render(){
        return(
          <form onSubmit={this.handleLogin}>
            用户名：<input onChange={this.saveUsername} type="text" name="username" /> <br/>
            密 码：<input onChange={this.savePassword} type="text" name="password"/> <br/>
            <input type="submit"/>
          </form>
        )
      }
    }

    ReactDOM.render(<Form/>,document.getElementById("app"))
  </script>
</body>

</html>